package com.onehouse.domain.payment.model.entity;

import com.onehouse.domain.payment.model.valobj.PaymentStatus;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;

@Data
public class OrderPaymentRequest {

    private String orderId;
    private ArrayList<Payment> payments;

    public void handleMethodPaymentPaidOff(String paymentId) {
        for (Payment payment : payments) {
            payment.setUpdateTime(LocalDateTime.now());
            if (payment.getPaymentId().equals(paymentId)) {
                payment.setStatus(PaymentStatus.SUCCESS);
            } else {
                payment.setStatus(PaymentStatus.FAILED);
            }
        }
    }

    public void handleTerminateOrderPaymentRequest() {
        for (Payment payment : payments) {
            payment.setUpdateTime(LocalDateTime.now());
            payment.setStatus(PaymentStatus.CANCELED);
        }
    }

}
